#include<iostream>
#include"contact.pb.h"
#include<string>
using std::endl;
using std::cout;
using std::cerr;
int main()
{
    std::string people_str;
    {
        contact::PersonInfo info1;
        info1.set_age(21);
        info1.set_name("张三");
        if(!info1.SerializeToString(&people_str))
        {
            cerr<<"序列化失败"<<endl;
            exit(-1);
        }        
        cout<<"序列化成功"<<endl;
        cout<<"people_str:"<<people_str<<endl;
        cout<<"---------------------------------"<<endl;
    }
    {
        contact::PersonInfo info1;
        
        if(!info1.ParseFromString(people_str))
        {
            cerr<<"反序列化失败"<<endl;
            exit(-1);
        }        
        cout<<"反序列化成功"<<endl;
        cout<<"name:"<<info1.name()<<endl;
        cout<<"age:"<<info1.age()<<endl;
    }

    return 0;
}

